package com.zeny.edu.ucenter.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zeny.edu.ucenter.entity.Member;
import com.zeny.edu.ucenter.mapper.MemberMapper;
import com.zeny.edu.ucenter.service.MemberService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 会员表 服务实现类
 * </p>
 *
 * @author zeny
 * @since 2020-03-08
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {

    /**
     * @Description 统计一天注册人数
     * @Date 2020/3/8 0008 16:40
     * @param day
     * @return java.lang.Integer
     **/
    @Override
    public Integer countRegisterByDay(String day) {
        return baseMapper.countRegisterByDay(day);
    }

    /**
     * @Description 保存用户到微博
     * @Date 2020/3/11 0011 18:12
     * @param member
     * @return com.zeny.edu.ucenter.entity.Member
     **/
    @Override
    public Member insertWeiboUser(Member member) {
        QueryWrapper<Member> wrapper = new QueryWrapper<>();
        wrapper.eq("openid", member.getOpenid());
        Member selectOne = baseMapper.selectOne(wrapper);
        if (selectOne == null) {
            baseMapper.insert(member);
            return member;
        }
        return selectOne;
    }
}
